package com.itrus.cert.util;

import com.itrus.cert.SignatureType;
import com.itrus.cryptorole.CryptoException;
import java.math.BigInteger;
import java.security.GeneralSecurityException;
import java.security.Principal;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.cert.X509Certificate;
import java.util.Date;
import java.util.Hashtable;
import java.util.Vector;
import org.bouncycastle.asn1.x509.X509Name;
import org.bouncycastle.jce.PKCS10CertificationRequest;
import org.bouncycastle.jce.X509Principal;
import org.bouncycastle.x509.X509V1CertificateGenerator;

public class X509CertUtils
{
  public static X509Certificate generateCert(String paramString1, String paramString2, String paramString3, String paramString4, String paramString5, String paramString6, String paramString7, int paramInt, PublicKey paramPublicKey, PrivateKey paramPrivateKey, SignatureType paramSignatureType)
    throws CryptoException
  {
    Hashtable localHashtable = new Hashtable();
    Vector localVector = new Vector();
    if (paramString1 != null)
    {
      localHashtable.put(X509Name.CN, paramString1);
      localVector.add(0, X509Name.CN);
    }
    if (paramString2 != null)
    {
      localHashtable.put(X509Name.OU, paramString2);
      localVector.add(0, X509Name.OU);
    }
    if (paramString3 != null)
    {
      localHashtable.put(X509Name.O, paramString3);
      localVector.add(0, X509Name.O);
    }
    if (paramString4 != null)
    {
      localHashtable.put(X509Name.L, paramString4);
      localVector.add(0, X509Name.L);
    }
    if (paramString5 != null)
    {
      localHashtable.put(X509Name.ST, paramString5);
      localVector.add(0, X509Name.ST);
    }
    if (paramString6 != null)
    {
      localHashtable.put(X509Name.C, paramString6);
      localVector.add(0, X509Name.C);
    }
    if (paramString7 != null)
    {
      localHashtable.put(X509Name.E, paramString7);
      localVector.add(0, X509Name.E);
    }
    X509V1CertificateGenerator localX509V1CertificateGenerator = new X509V1CertificateGenerator();
    localX509V1CertificateGenerator.setIssuerDN(new X509Principal(localVector, localHashtable));
    localX509V1CertificateGenerator.setNotBefore(new Date(System.currentTimeMillis()));
    localX509V1CertificateGenerator.setNotAfter(new Date(System.currentTimeMillis() + 1000L * (60L * (60L * (24L * paramInt)))));
    localX509V1CertificateGenerator.setSubjectDN(new X509Principal(localVector, localHashtable));
    localX509V1CertificateGenerator.setPublicKey(paramPublicKey);
    localX509V1CertificateGenerator.setSignatureAlgorithm(paramSignatureType.name());
    localX509V1CertificateGenerator.setSerialNumber(generateX509SerialNumber());
    try
    {
      X509Certificate localX509Certificate = localX509V1CertificateGenerator.generate(paramPrivateKey, "BC");
      return localX509Certificate;
    }
    catch (GeneralSecurityException localGeneralSecurityException)
    {
      throw new CryptoException("Certificate generation failed.", localGeneralSecurityException);
    }
  }

  public static PKCS10CertificationRequest generatePKCS10CSR(X509Certificate paramX509Certificate, PrivateKey paramPrivateKey)
    throws CryptoException
  {
    X509Name localX509Name = new X509Name(paramX509Certificate.getSubjectDN().toString());
    PKCS10CertificationRequest localPKCS10CertificationRequest;
    try
    {
      localPKCS10CertificationRequest = new PKCS10CertificationRequest(paramX509Certificate.getSigAlgName(), localX509Name, paramX509Certificate.getPublicKey(), null, paramPrivateKey);
      if (!localPKCS10CertificationRequest.verify())
        throw new CryptoException("Could not verify generated certification request.");
    }
    catch (GeneralSecurityException localGeneralSecurityException)
    {
      throw new CryptoException("Could not generate a certification request.", localGeneralSecurityException);
    }
    return localPKCS10CertificationRequest;
  }

  private static BigInteger generateX509SerialNumber()
  {
    return new BigInteger(Long.toString(System.currentTimeMillis() / 1000L));
  }
}

/* Location:           C:\Users\user\Desktop\dd28_pcdd720\classes_dex2jar.jar
 * Qualified Name:     com.itrus.cert.util.X509CertUtils
 * JD-Core Version:    0.6.2
 */